package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllMeetings", query = "select myMeeting from Meeting myMeeting"),
		@NamedQuery(name = "findMeetingByEndDate", query = "select myMeeting from Meeting myMeeting where myMeeting.endDate = ?1"),
		@NamedQuery(name = "findMeetingById", query = "select myMeeting from Meeting myMeeting where myMeeting.id = ?1"),
		@NamedQuery(name = "findMeetingByLocation", query = "select myMeeting from Meeting myMeeting where myMeeting.location = ?1"),
		@NamedQuery(name = "findMeetingByLocationContaining", query = "select myMeeting from Meeting myMeeting where myMeeting.location like ?1"),
		@NamedQuery(name = "findMeetingByMessage", query = "select myMeeting from Meeting myMeeting where myMeeting.message = ?1"),
		@NamedQuery(name = "findMeetingByPrimaryKey", query = "select myMeeting from Meeting myMeeting where myMeeting.id = ?1"),
		@NamedQuery(name = "findMeetingByRemind", query = "select myMeeting from Meeting myMeeting where myMeeting.remind = ?1"),
		@NamedQuery(name = "findMeetingByRemindContaining", query = "select myMeeting from Meeting myMeeting where myMeeting.remind like ?1"),
		@NamedQuery(name = "findMeetingByRepeat", query = "select myMeeting from Meeting myMeeting where myMeeting.repeat = ?1"),
		@NamedQuery(name = "findMeetingByRepeatContaining", query = "select myMeeting from Meeting myMeeting where myMeeting.repeat like ?1"),
		@NamedQuery(name = "findMeetingBySentDate", query = "select myMeeting from Meeting myMeeting where myMeeting.sentDate = ?1"),
		@NamedQuery(name = "findMeetingByStartDate", query = "select myMeeting from Meeting myMeeting where myMeeting.startDate = ?1"),
		@NamedQuery(name = "findMeetingByTitle", query = "select myMeeting from Meeting myMeeting where myMeeting.title = ?1"),
		@NamedQuery(name = "findMeetingByTitleContaining", query = "select myMeeting from Meeting myMeeting where myMeeting.title like ?1") })
@Table(catalog = "sow", name = "meeting")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "Meeting")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class Meeting implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "TITLE", length = 100, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String title;
	/**
	 */

	@Column(name = "LOCATION", length = 100)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String location;
	/**
	 */

	@Column(name = "MESSAGE", columnDefinition = "TEXT")
	@Basic(fetch = FetchType.EAGER)
	@Lob
	@XmlElement
	String message;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "START_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar startDate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "END_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar endDate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "SENT_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar sentDate;
	/**
	 */

	@Column(name = "REPEAT", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String repeat;
	/**
	 */

	@Column(name = "REMIND", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String remind;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "SENT_BY", referencedColumnName = "ID") })
	@XmlTransient
	User user;
	/**
	 */
	@OneToMany(mappedBy = "meeting", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.MeetingRecipient> meetingRecipients;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 */
	public String getTitle() {
		return this.title;
	}

	/**
	 */
	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 */
	public String getLocation() {
		return this.location;
	}

	/**
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 */
	public String getMessage() {
		return this.message;
	}

	/**
	 */
	public void setStartDate(Calendar startDate) {
		this.startDate = startDate;
	}

	/**
	 */
	public Calendar getStartDate() {
		return this.startDate;
	}

	/**
	 */
	public void setEndDate(Calendar endDate) {
		this.endDate = endDate;
	}

	/**
	 */
	public Calendar getEndDate() {
		return this.endDate;
	}

	/**
	 */
	public void setSentDate(Calendar sentDate) {
		this.sentDate = sentDate;
	}

	/**
	 */
	public Calendar getSentDate() {
		return this.sentDate;
	}

	/**
	 */
	public void setRepeat(String repeat) {
		this.repeat = repeat;
	}

	/**
	 */
	public String getRepeat() {
		return this.repeat;
	}

	/**
	 */
	public void setRemind(String remind) {
		this.remind = remind;
	}

	/**
	 */
	public String getRemind() {
		return this.remind;
	}

	/**
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 */
	@JsonIgnore
	public User getUser() {
		return user;
	}

	/**
	 */
	public void setMeetingRecipients(Set<MeetingRecipient> meetingRecipients) {
		this.meetingRecipients = meetingRecipients;
	}

	/**
	 */
	@JsonIgnore
	public Set<MeetingRecipient> getMeetingRecipients() {
		if (meetingRecipients == null) {
			meetingRecipients = new java.util.LinkedHashSet<edu.hcmus.sow.domain.MeetingRecipient>();
		}
		return meetingRecipients;
	}

	/**
	 */
	public Meeting() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Meeting that) {
		setId(that.getId());
		setTitle(that.getTitle());
		setLocation(that.getLocation());
		setMessage(that.getMessage());
		setStartDate(that.getStartDate());
		setEndDate(that.getEndDate());
		setSentDate(that.getSentDate());
		setRepeat(that.getRepeat());
		setRemind(that.getRemind());
		setUser(that.getUser());
		setMeetingRecipients(new java.util.LinkedHashSet<edu.hcmus.sow.domain.MeetingRecipient>(that.getMeetingRecipients()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("title=[").append(title).append("] ");
		buffer.append("location=[").append(location).append("] ");
		buffer.append("message=[").append(message).append("] ");
		buffer.append("startDate=[").append(startDate).append("] ");
		buffer.append("endDate=[").append(endDate).append("] ");
		buffer.append("sentDate=[").append(sentDate).append("] ");
		buffer.append("repeat=[").append(repeat).append("] ");
		buffer.append("remind=[").append(remind).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Meeting))
			return false;
		Meeting equalCheck = (Meeting) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
